window.onload = function () {
    var setHeight = function(e){
		console.log($(e).height())
		//$("#hot_goods .banner").height($(e).height()); 
	}
	
	ajax(api.getSecKills,{},function(data){
		console.log("home data 1 : ",data)
		
		// 轮播图
		//banner
		if(data.banners != null){
			for(var i=0;i<data.banners.length;i++){
				$(".slider ul").append("<li onclick='urlClick(0,\""+data.banners[i].url+"\")'><img onload=\"img_onload(this)\" style=\"width:"+window.screen.width+"px;height:"+window.screen.width*175/375+"px\" src=\""+data.banners[i].img_url+"\"></li>")
			}
			$(".slider").yxMobileSlider({width:window.screen.width,during:3000,height:window.screen.width*175/375})
		}
		
		//加载top
		$("#seckill_top").setTemplateURL('tmpl/seckillTop.html');
		$("#seckill_top").setParam("width", window.screen.width); 
		$("#seckill_top").processTemplate(data.products);
		
		//购物车状态
		gouwuche_changed()
		//评论下拉刷新控件
	    $('#box').load("comm/loadmore.html", function(data){
			loaded(0, {url:api.toHomeData, page:'tmpl/homeTmpl.html', para:{}})
		});
	})
}

//图片加载
function img_onload(obj){
	obj.width=window.screen.width
}

function myShopping(){
	window.location.href="myShoppingCart.html"
}

function goHome(){
	window.location.href="home.html"
}

function goSeckill(){
	window.location.href="seckills.html"
}

function memberClick(){
	window.location.href="http://cs.tzfwzx.cn/fishing/site/user/index"
}

//详情点击
function locationClick(id){
	window.location.href="goods.html?id="+id;
}

//购物车图标更改
function gouwuche_changed(){
	ajax(api.getCartItemNum, {}, function(data){
		if(data != null && data.num != null && data.num != 0){
			if(data.num>99){
				$(".badge").text("99+")
			}else if(data.num>9){
				$(".badge").text(data.num)
			}else{
				$(".badge").text(data.num)
			}
			$(".badge").css("display","block")
		}else{
			$(".badge").css("display","none")
		}
	})
}

//gotop
function gotop(){
	$('#toppage').animate({scrollTop:0},500);
	 return false;
}
